package topcbl.taxi;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class TaxiDriverDialog extends Dialog {

	TextView tvDriverName, tvCarNumber, tvTel, tvAge, tvExp;
	ImageView btnCallDriver, btnCallTaxi;
	Context context;

	public TaxiDriverDialog(Context context) {
		super(context);
		this.context = context;
		// animation
		getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
		// requestWindowFeature(Window.FEATURE_NO_TITLE);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_taxi_driver);
		setTitle(getContext().getString(R.string.titleDriverInformation));

		this.tvDriverName = (TextView) findViewById(R.id.tvDriverName);
		this.tvCarNumber = (TextView) findViewById(R.id.tvCarNumber);
		this.tvTel = (TextView) findViewById(R.id.tvTel);

		ImageButton ibtnClose = (ImageButton) findViewById(R.id.ibtnAllCarType);
		ibtnClose.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				TaxiDriverDialog.this.dismiss();
			}
		});
		initButton();
		// Typeface custom_font =
		// Typeface.createFromAsset(context.getAssets(),"fonts/times.ttf");
		// tx.setTypeface(custom_font);
		/*
		 * Resources resources = getContext().getResources(); int color =
		 * resources.getColor(R.color.tone_orange);
		 * 
		 * int alertTitleId = resources.getIdentifier("alertTitle", "id",
		 * "android"); TextView alertTitle = (TextView)
		 * getWindow().getDecorView().findViewById(alertTitleId);
		 * alertTitle.setTextColor(color); // change title text color
		 * 
		 * int titleDividerId = resources.getIdentifier("titleDivider", "id",
		 * "android"); View titleDivider =
		 * getWindow().getDecorView().findViewById(titleDividerId);
		 * titleDivider.setBackgroundColor(color); // change divider color
		 */

		// set the custom dialog components - text, image and button
		// if button is clicked, close the custom dialog
	}

	public void setContent(String DriverName, String CarNumber, String Tel) {
		tvDriverName.setText(DriverName);
		tvCarNumber.setText(CarNumber);
		tvTel.setText(Tel);
	}

	private void initButton() {
		btnCallDriver = (ImageView) findViewById(R.id.imageView4);
		btnCallTaxi = (ImageView) findViewById(R.id.imageView5);
		btnCallDriver.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				String mobile = tvTel.getText() + "";
				if (mobile != null && mobile.length() > 0) {
					Uri uri = Uri.parse("tel:" + mobile);
					Intent phonecall = new Intent(Intent.ACTION_CALL, uri);
					context.startActivity(phonecall);
				}
			}
		});
		btnCallTaxi.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				MainActivity.mBindService.getService().turnOnChatHead();
				dismiss();
				((CallTaxiActivity) context).moveTaskToBack(true);
				((CallTaxiActivity) context).finish();
				Toast.makeText(context,
						context.getString(R.string.taxi_comming),
						Toast.LENGTH_LONG).show();
			}
		});
	}
}
